package engine.data;

import util.ArrayList;
import util.List;

public final class Technology {

	public static final byte NONE = -1;

	public static final byte ADVANCED_FLIGHT = 0;

	public static final byte ALPHABET = 1;

	public static final byte ASTRONOMY = 2;

	public static final byte ATOMIC_THEORY = 3;

	public static final byte AUTOMOBILE = 4;

	public static final byte BANKING = 5;

	public static final byte BRIDGE_BUILDING = 6;

	public static final byte BRONZE_WORKING = 7;

	public static final byte CEREMONIAL_BURIAL = 8;

	public static final byte CHEMISTRY = 9;

	public static final byte CHIVALRY = 10;

	public static final byte COMBUSTION = 11;

	public static final byte COMMUNISM = 12;

	public static final byte COMPUTERS = 13;

	public static final byte CONSCRIPTION = 14;

	public static final byte CONSTRUCTION = 15;

	public static final byte CODE_OF_LAWS = 16;

	public static final byte CURRENCY = 17;

	public static final byte DEMOCRATY = 18;

	public static final byte ELECTRICITY = 19;

	public static final byte ELECTRONICS = 20;

	public static final byte ENGINEERING = 21;

	public static final byte EXPLOSIVES = 22;

	public static final byte FEUDALISM = 23;

	public static final byte FLIGHT = 24;

	public static final byte FUSION_POWER = 25;

	public static final byte GENETIC_ENGINEERING = 26;

	public static final byte GUNPOWDER = 27;

	public static final byte HORSEBACK_RIDING = 28;

	public static final byte INDUSTRIALIZATION = 29;

	public static final byte INVENTION = 30;

	public static final byte IRON_WORKING = 31;

	public static final byte LABOR_UNION = 32;

	public static final byte LITERACY = 33;

	public static final byte MAGNETISM = 34;

	public static final byte MAP_MAKING = 35;

	public static final byte MASONRY = 36;

	public static final byte MASS_PRODUCTION = 37;

	public static final byte MATHEMATICS = 38;

	public static final byte MEDICINE = 39;

	public static final byte METALLURGY = 40;

	public static final byte MYSTICISM = 41;

	public static final byte MONARCHY = 42;

	public static final byte NAVIGATION = 43;

	public static final byte NUCLEAR_FISSION = 44;

	public static final byte NUCLEAR_POWER = 45;

	public static final byte PHILOSOPHY = 46;

	public static final byte PHYSICS = 47;

	public static final byte PLASTICS = 48;

	public static final byte POTTERY = 49;

	public static final byte RAILROAD = 50;

	public static final byte RECYCLING = 51;

	public static final byte REFINING = 52;

	public static final byte RELIGION = 53;

	public static final byte ROBOTICS = 54;

	public static final byte ROCKETRY = 55;

	public static final byte SPACE_FLIGHT = 56;

	public static final byte STEAM_ENGINE = 57;

	public static final byte STEEL = 58;

	public static final byte SUPERCONDUCTOR = 59;

	public static final byte THE_CORPORATION = 60;

	public static final byte THE_REPUBLIC = 61;

	public static final byte THEORY_OF_GRAVITY = 62;

	public static final byte THE_WHEEL = 63;

	public static final byte TRADE = 64;

	public static final byte UNIVERSITY = 65;

	public static final byte WRITING = 66;

	public static final byte SIZE = 67;

	private static final byte[][] REQUIRED_TECH = new byte[SIZE][2];

	static {
		REQUIRED_TECH[ADVANCED_FLIGHT] = new byte[] { FLIGHT, ELECTRICITY };
		REQUIRED_TECH[ALPHABET] = null;
		REQUIRED_TECH[ASTRONOMY] = new byte[] { MYSTICISM, MATHEMATICS };
		REQUIRED_TECH[ATOMIC_THEORY] = new byte[] { THEORY_OF_GRAVITY, PHYSICS };
		REQUIRED_TECH[AUTOMOBILE] = new byte[] { COMBUSTION, STEEL };
		REQUIRED_TECH[BANKING] = new byte[] { TRADE, THE_REPUBLIC };
		REQUIRED_TECH[BRIDGE_BUILDING] = new byte[] { CONSTRUCTION, IRON_WORKING };
		REQUIRED_TECH[BRONZE_WORKING] = null;
		REQUIRED_TECH[CEREMONIAL_BURIAL] = null;
		REQUIRED_TECH[CHEMISTRY] = new byte[] { UNIVERSITY, MEDICINE };
		REQUIRED_TECH[CHIVALRY] = new byte[] { HORSEBACK_RIDING, FEUDALISM };
		REQUIRED_TECH[CODE_OF_LAWS] = null;
		REQUIRED_TECH[COMBUSTION] = new byte[] { REFINING, EXPLOSIVES };
		REQUIRED_TECH[COMMUNISM] = new byte[] { PHILOSOPHY, INDUSTRIALIZATION };
		REQUIRED_TECH[COMPUTERS] = new byte[] { MATHEMATICS, ELECTRONICS };
		REQUIRED_TECH[CONSCRIPTION] = new byte[] { THE_REPUBLIC, EXPLOSIVES };
		REQUIRED_TECH[CONSTRUCTION] = new byte[] { MASONRY, CURRENCY };
		REQUIRED_TECH[CURRENCY] = null;
		REQUIRED_TECH[DEMOCRATY] = new byte[] { PHILOSOPHY, LITERACY };
		REQUIRED_TECH[ELECTRICITY] = new byte[] { METALLURGY, MAGNETISM };
		REQUIRED_TECH[ELECTRONICS] = new byte[] { ENGINEERING, ELECTRICITY };
		REQUIRED_TECH[ENGINEERING] = new byte[] { THE_WHEEL, CONSTRUCTION };
		REQUIRED_TECH[EXPLOSIVES] = new byte[] { GUNPOWDER, CHEMISTRY };
		REQUIRED_TECH[FEUDALISM] = new byte[] { MASONRY, MONARCHY };
		REQUIRED_TECH[FLIGHT] = new byte[] { COMBUSTION, PHYSICS };
		REQUIRED_TECH[FUSION_POWER] = new byte[] { NUCLEAR_POWER, SUPERCONDUCTOR };
		REQUIRED_TECH[GENETIC_ENGINEERING] = new byte[] { MEDICINE, THE_CORPORATION };
		REQUIRED_TECH[GUNPOWDER] = new byte[] { INVENTION, IRON_WORKING };
		REQUIRED_TECH[HORSEBACK_RIDING] = null;
		REQUIRED_TECH[INDUSTRIALIZATION] = new byte[] { RAILROAD, BANKING };
		REQUIRED_TECH[INVENTION] = new byte[] { ENGINEERING, LITERACY };
		REQUIRED_TECH[IRON_WORKING] = null;
		REQUIRED_TECH[LABOR_UNION] = new byte[] { MASS_PRODUCTION, COMMUNISM };
		REQUIRED_TECH[LITERACY] = new byte[] { WRITING, CODE_OF_LAWS };
		REQUIRED_TECH[MAGNETISM] = new byte[] { NAVIGATION, PHYSICS };
		REQUIRED_TECH[MAP_MAKING] = null;
		REQUIRED_TECH[MASONRY] = null;
		REQUIRED_TECH[MASS_PRODUCTION] = new byte[] { AUTOMOBILE, THE_CORPORATION };
		REQUIRED_TECH[MATHEMATICS] = new byte[] { ALPHABET, MASONRY };
		REQUIRED_TECH[MEDICINE] = new byte[] { PHILOSOPHY, TRADE };
		REQUIRED_TECH[METALLURGY] = new byte[] { GUNPOWDER, UNIVERSITY };
		REQUIRED_TECH[MYSTICISM] = null;
		REQUIRED_TECH[MONARCHY] = new byte[] { CEREMONIAL_BURIAL, CODE_OF_LAWS };
		REQUIRED_TECH[NAVIGATION] = new byte[] { MAP_MAKING, ASTRONOMY };
		REQUIRED_TECH[NUCLEAR_FISSION] = new byte[] { ATOMIC_THEORY, MASS_PRODUCTION };
		REQUIRED_TECH[NUCLEAR_POWER] = new byte[] { ELECTRONICS, NUCLEAR_FISSION };
		REQUIRED_TECH[PHILOSOPHY] = new byte[] { MYSTICISM, LITERACY };
		REQUIRED_TECH[PHYSICS] = new byte[] { MATHEMATICS, NAVIGATION };
		REQUIRED_TECH[PLASTICS] = new byte[] { REFINING, SPACE_FLIGHT };
		REQUIRED_TECH[POTTERY] = null;
		REQUIRED_TECH[RAILROAD] = new byte[] { STEAM_ENGINE, BRIDGE_BUILDING };
		REQUIRED_TECH[RECYCLING] = new byte[] { MASS_PRODUCTION, DEMOCRATY };
		REQUIRED_TECH[REFINING] = new byte[] { CHEMISTRY, THE_CORPORATION };
		REQUIRED_TECH[RELIGION] = new byte[] { PHILOSOPHY, WRITING };
		REQUIRED_TECH[ROBOTICS] = new byte[] { PLASTICS, COMPUTERS };
		REQUIRED_TECH[ROCKETRY] = new byte[] { ADVANCED_FLIGHT, ELECTRONICS };
		REQUIRED_TECH[SPACE_FLIGHT] = new byte[] { COMPUTERS, ROCKETRY };
		REQUIRED_TECH[STEAM_ENGINE] = new byte[] { PHYSICS, INVENTION };
		REQUIRED_TECH[STEEL] = new byte[] { METALLURGY, INDUSTRIALIZATION };
		REQUIRED_TECH[SUPERCONDUCTOR] = new byte[] { PLASTICS, MASS_PRODUCTION };
		REQUIRED_TECH[THE_CORPORATION] = new byte[] { BANKING, INDUSTRIALIZATION };
		REQUIRED_TECH[THE_REPUBLIC] = new byte[] { CODE_OF_LAWS, LITERACY };
		REQUIRED_TECH[THEORY_OF_GRAVITY] = new byte[] { ASTRONOMY, UNIVERSITY };
		REQUIRED_TECH[TRADE] = new byte[] { CURRENCY, CODE_OF_LAWS };
		REQUIRED_TECH[THE_WHEEL] = null;
		REQUIRED_TECH[UNIVERSITY] = new byte[] { MATHEMATICS, PHILOSOPHY };
		REQUIRED_TECH[WRITING] = null;
	}

	private Technology() {
		// no constructor
	}

	private static final String[] NAME = { "Advanced Flight", "Alphabet", "Astronomy", "Atomic Theory", "Automobile",
			"Banking", "Bridge Building", "Bronze Working", "Ceremonial Burial", "Chemistry", "Chivalry",
			"Code of Laws", "Combustion", "Communism", "Computers", "Conscription", "Construction", "Currency",
			"Democracy", "Electricity", "Electronics", "Engineering", "Explosives", "Feudalism", "Flight",
			"Fusion Power", "Genetic Engineering", "Gunpowder", "Horseback Riding", "Industrialization", "Invention",
			"Iron Working", "Labor Union", "Literacy", "Magnetism", "Map Making", "Masonry", "Mass Production",
			"Mathematics", "Medicine", "Metallurgy", "Monarchy", "Mysticism", "Navigation", "Nuclear Fission",
			"Nuclear Power", "Philosophy", "Physics", "Plastics", "Pottery", "Railroad", "Recycling", "Refining",
			"Robotics", "Rocketry", "Space Flight", "Steam Engine", "Steel", "Superconductors", "The Corporation",
			"The Republic", "The Wheel", "Religion", "Theory of Gravity", "Trade", "University", "Writing" };

	public static String getName(final byte id) {
		return NAME[id];
	}

	public static List getPreviousAdvances(final byte techId) {
		List ret = new ArrayList();
		getPreviousAdvances(ret, techId);
		if (ret.size() > 0)
			return ret;
		return null;
	}

	private static void getPreviousAdvances(final List ret, final byte techId) {
		if (REQUIRED_TECH[techId] != null) {
			getPreviousAdvances(ret, REQUIRED_TECH[techId][0]);
			getPreviousAdvances(ret, REQUIRED_TECH[techId][1]);
			if (!ret.contains(new Byte(techId)))
				ret.add(new Byte(techId));
		}
	}

	public static List getPossibleTechnologiesIds(final List techs) {
		List ret = new ArrayList();
		for (byte i = 0; i < SIZE; i++) {
			if (!techs.contains(new Byte(i)))
				if (REQUIRED_TECH[i] != null) {
					if (techs.contains(new Byte(REQUIRED_TECH[i][0])) && techs.contains(new Byte(REQUIRED_TECH[i][1])))
						ret.add(new Byte(i));
				} else
					ret.add(new Byte(i));
		}
		return ret;
	}
}
